package ace.module.captcha.sms.core.impl.dao.aggregate.impl;

import ace.module.captcha.sms.core.impl.dao.aggregate.CaptchaSmsItemAggregate;
import ace.module.captcha.sms.core.impl.dao.entity.QCaptchaSmsItem;
import ace.module.captcha.sms.core.impl.dao.repository.CaptchaSmsItemRepository;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
* 验证码 aggregate implement.
*
* @author Caspar
*/
@Slf4j
@AllArgsConstructor
@Component
public class CaptchaSmsItemAggregateImpl implements CaptchaSmsItemAggregate {
  private final CaptchaSmsItemRepository captchaSmsItemRepository;

  @Override
  public void remove(Long captchaSmsAppId, String phone) {

    Predicate deleteWhere =
        ExpressionUtils.allOf(
            QCaptchaSmsItem.captchaSmsItem.captchaSmsAppId.eq(captchaSmsAppId),
            QCaptchaSmsItem.captchaSmsItem.phone.eq(phone));

    this.captchaSmsItemRepository.deleteWhere(deleteWhere);
  }
}
